package com.uikoo9.util.jfinal;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.render.FreeMarkerRender;
import com.uikoo9.plugin.QuartzPlugin1;
import com.uikoo9.util.core.file.QPropertiesUtil;
import com.uikoo9.z.MyInterceptor;

/**
 * jfinal config
 * @author qiaowenbin
 * @version 0.0.4.20140909
 */
public class QJfinalConfig1 extends JFinalConfig{

    @Override
    public void configConstant(Constants me) {
        me.setDevMode(QPropertiesUtil.getPropertyToBoolean(QPropertiesUtil.config, "jfinal.dev_mode"));
    }

    @Override
    public void configRoute(Routes me) {
        QJfinalUtil.initController(me);
    }

    @Override
    public void configPlugin(Plugins me) {
        QJfinalUtil.initDbAndArp(me);

        //孔令宝 2015年6月15日 17:23:59 增加 plugin
        QuartzPlugin1 quartzPlugin = new QuartzPlugin1("job.properties");
        me.add(quartzPlugin);

        FreeMarkerRender.setProperty("template_update_delay", "0");//模板更更新时间,0表示每次都加载
        FreeMarkerRender.setProperty("classic_compatible", "true");//如果为null则转为空值,不需要再用!处理
        FreeMarkerRender.setProperty("whitespace_stripping", "true");//去除首尾多余空格
        FreeMarkerRender.setProperty("date_format", "yyyy-MM-dd");
        FreeMarkerRender.setProperty("time_format", "HH:mm:ss");
        FreeMarkerRender.setProperty("datetime_format", "yyyy-MM-dd HH:mm:ss");
        FreeMarkerRender.setProperty("default_encoding", "UTF-8");

    }

    @Override
    public void configInterceptor(Interceptors me) {
        me.add(new QInterceptor1());
        me.add(new MyInterceptor());// 自定义全局拦截器
        me.add(new QRequestInter());
    }

    @Override
    public void configHandler(Handlers me) {
    }

    @Override
    public void afterJFinalStart() {
        QJfinalUtil.initFiles();
    }

}